<?php

namespace App\Http\Controllers\Api\V1;

use App\Enums\ResponseCode;
use App\Exceptions\ApiExceptions;
use App\Http\Controllers\Api\AbstractApiController;
use App\Services\Feedback\FeedbackService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FeedbackController extends AbstractApiController
{
    /**
     * 初始化数据
     * @return JsonResponse
     */
    public function init(): JsonResponse
    {
        $result = FeedbackService::init();
        return self::success(trans("success"), ResponseCode::OK, $result);
    }

    /**
     * 提交工单
     * @param Request $request
     * @return JsonResponse
     * @throws ApiExceptions
     */
    public function create(Request $request): JsonResponse
    {
        $input = $request->validate([
            'job_position_id' => 'required|int|min:1',
            'scene' => 'required|int',
            'content' => 'required',
            'feed_pic' => 'array',
        ]);
        FeedbackService::create(
            userId: auth('api')->id(),
            scene: $input['scene'],
            content: $input['content'],
            job_position_id: $input['job_position_id'],
            feed_pic: $input['feed_pic']??[]
        );
        return self::success(trans("举报成功，正在处理中"));
    }

    /**
     * 留言列表
     * @param Request $request
     * @return JsonResponse
     */
    public function lists(Request $request): JsonResponse
    {
        $result = FeedbackService::lists(auth('api')->id());
        return $this->success(trans("success"), ResponseCode::OK, $result);
    }
}
